package utils

import (
	"net/smtp"
	"strings"
)

func SendToMail(user, sendUserName, password, host, subject, body, mailtype string, to []string) error {
	hp := strings.Split(host, ":")
	auth := smtp.PlainAuth("", user, password, hp[0])
	var content_type string
	if mailtype == "html" {
		content_type = "Content-Type: text/" + mailtype + "; charset=UTF-8"
	} else {
		content_type = "Content-Type: text/plain" + "; charset=UTF-8"
	}
	var sent_to string
	sent_to = strings.Join(to, ";")
	msg := []byte("To: " + sent_to + "\r\nFrom: " + sendUserName + "<" + user + ">" + "\r\nSubject: " + subject + "\r\n" + content_type + "\r\n\r\n" + body)
	err := smtp.SendMail(host, auth, user, to, msg)
	return err
}
